﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

using Ninject;

namespace ecdl.demo.model.expression {
    public class And : CompositeExpression {
        public And() {
        }

        public override ExpressionState Evaluate(ExpressionContext context) {
            bool result = true;
            IEnumerator<Expression> expressionEnumerator = Expressions.AsEnumerable<Expression>().GetEnumerator();
            MultiExpressionState expressionState = new MultiExpressionState(this);

            while (expressionEnumerator.MoveNext()) {
                ExpressionState childState = expressionEnumerator.Current.Evaluate(context);
                expressionState.ChildExpressions.Add(childState);

                result &= childState.IsOk;
            }
            expressionState.IsOk = result;

            return expressionState;
        }
    }

    public class AndDTO : MultiExpressionDTO{
        public AndDTO() : base(typeof(And)){
        }
    }
}
